<template>
  <div>
    <div class="list-title">
      <van-icon name="arrow-left" size="25" color="#fff" class="title-icon" />
      <div class="list-big">
        <div class="input-title">
          <div class="title-left" @click="$router.push('/city')">
            <p>{{ cityName }}</p>
            <van-icon
              class="iconfont"
              class-prefix="icon"
              name="xialakuangxiala"
              size="28px"
              color="#7f7f80"
            />
          </div>
          <div class="title-right">
            <van-icon name="search" size="20" color="#ccc" />
            <input type="text" placeholder="请输入小区或地址" />
          </div>
        </div>
      </div>
      <van-icon
        class="iconfont icons"
        class-prefix="icon"
        name="dituzhaofang"
        size="25"
        color="#fff"
      />
    </div>
    <van-dropdown-menu>
      <van-dropdown-item title="区域">
        <van-picker :columns="column" />
        <div class="button-style">
          <van-button type="default" class="buttons">取消</van-button>
          <van-button type="primary" class="buttones">确定</van-button>
        </div>
      </van-dropdown-item>
      <van-dropdown-item title="方式">
        <van-picker :columns="columns" item-height="36" />
        <div class="button-style">
          <van-button type="default" class="buttons">取消</van-button>
          <van-button type="primary" class="buttones">确定</van-button>
        </div>
      </van-dropdown-item>
      <van-dropdown-item title="租金">
        <van-picker :columns="columnss" item-height="36" />
        <div class="button-style">
          <van-button type="default" class="buttons">取消</van-button>
          <van-button type="primary" class="buttones">确定</van-button>
        </div>
      </van-dropdown-item>
      <van-dropdown-item title="筛选" v-model="showPopup" :overlay="false">
        <van-popup
          v-model="showPopup"
          position="top"
          :style="{ height: '30%' }"
        >
          <div>回到家就好好</div>
        </van-popup>
        <div class="button-style">
          <van-button type="default" class="buttons">取消</van-button>
          <van-button type="primary" class="buttones">确定</van-button>
        </div>
      </van-dropdown-item>
    </van-dropdown-menu>

    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <ListItem :info="list"></ListItem>
    </van-list>
  </div>
</template>

<script>
import { houseList } from '@/api/house'
import { nameCity } from '@/api/area'
import { mapState } from 'vuex'
export default {
  name: 'ListPage',
  data () {
    return {
      list: [],
      loading: false,
      finished: false,
      column: [
        {
          text: '区域',
          children: [
            {
              text: '杭州',
              children: [{ text: '西湖区' }, { text: '余杭区' }]
            },
            {
              text: '温州',
              children: [{ text: '鹿城区' }, { text: '瓯海区' }]
            }
          ]
        },
        {
          text: '地铁',
          children: [
            {
              text: '福州',
              children: [{ text: '鼓楼区' }, { text: '台江区' }]
            },
            {
              text: '厦门',
              children: [{ text: '思明区' }, { text: '海沧区' }]
            }
          ]
        }
      ],
      columns: ['不限', '整租', '合租'],
      columnss: [
        '不限',
        '1000及以下',
        '1000 - 2000',
        '2000 - 3000',
        '3000 - 4000',
        '4000 - 5000',
        '5000 - 7000',
        '7000以上'
      ],
      showPopup: false,
      name: '上海',
      queryObj: {
        cityId: this.cityId,
        start: 1,
        end: 20
      }

    }
  },
  methods: {
    async onLoad () {
      const data = await houseList(this.queryObj)
      console.log(data)
      this.list = [...this.list, ...data.body.list]
      this.loading = false
      this.queryObj.start += 20
      this.queryObj.end += 20
      // this.finished = true
    },
    onConfirm (value) {
      this.value = value
      this.showPicker = false
    }
    // showPopup () {
    //   this.show = true
    // }
  },
  // async created () {
  //   const data = await houseList()
  //   console.log(data)
  //   this.info = data.body.list
  // }

  async created () {
    const data = await nameCity(this.name)
    console.log(data)
    // this.info = data.body.list
  },
  computed: {
    ...mapState('user', ['cityName', 'cityId'])
  }
}
</script>

<style scoped lang="less">
* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}
.findList {
  ul {
    width: 100%;
    li {
      height: 120px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      border-bottom: 1px solid #ccc;
      padding: 15px;
      .imgs {
        width: 120px;
        height: 100%;
        background-color: brown;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .list-content {
        flex: 1;
        height: 100%;
        margin-left: 10px;
        font-size: 12px;
        h3 {
          font-size: 15px;
          color: #394043;
        }
        .adress {
          color: #afb2b3;
          margin: 5px 0;
        }
        .distance {
          width: 50px;
          height: 25px;
          background-color: #e1f5f8;
          border-radius: 3px;
          color: #39becd;
          text-align: center;
          line-height: 25px;
          margin-bottom: 5px;
        }
        .housePrice {
          color: #fa5741;
          span {
            font-size: 16px;
          }
        }
      }
    }
  }
}
.list-title {
  width: 375px;
  width: 50px;
  background-color: #21b97a;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .title-icon {
    padding-right: -10px;
    margin: 0 10px;
  }
  .icons {
    height: 50px;
    line-height: 50px;
    padding: 0 20px;
    background-color: #21b97a;
  }
  .list-big {
    width: 270px;
    height: 50px;
    background-color: #21b97a;
    .input-title {
      height: 35px;
      background-color: #fff;
      display: flex;
      justify-content: start;
      align-items: center;
      margin-top: 7px;
      border-radius: 5px;
      color: #9c9fa1;
      font-size: 13px;
      .title-left {
        width: 70px;
        border-right: 1px solid #ccc;
        color: #333;
        display: flex;
        align-items: center;
        justify-content: center;
      }
      .title-right {
        width: 185px;
        margin-left: 10px;
        display: flex;
        input {
          border: none;
          margin-left: 5px;
        }
      }
    }
  }
}
.button-style {
  display: flex;
  .buttons {
    width: 125px;
  }
  .buttones {
    flex: 1;
  }
}
</style>
